function reg() {
    var username = document.getElementById("username").value;
    var pwd = document.getElementById("password").value;
    var rwd = document.getElementById("repassword").value;
    if (username == "") {
        alert("用户账号不能为空");
        return false;
    }
    if (pwd == "" || rwd == "") {
        alert("密码不能为空");
        return false;
    }
    if (pwd != rwd) {
        alert("两次密码不同！");
        return false;
    }

    fetch('/register',{
        method: 'POST',
        headers:{
            'ConTent-Type': 'application/json'
        },
        body:JSON.stringify({
            username: username,
            password: pwd
        })
    })
        .then(response =>response.json())
        .then(data =>{
            if (data.success){
                alert("注册成功");
                window.location = '/login';
            }else {
                alert("存在该用户名，请重新输入");
            }
        })
}

function reset() {
    // 清空输入框内容
    document.getElementById("username").value = '';
    document.getElementById("password").value = '';
    document.getElementById("repassword").value = '';
}
